module PrettyJSONTest(tests) where

import Test.HUnit
import Prettify
import PrettyJSON
import SimpleJSON

docSimpleTest name expected source =
    name ~: text expected @=? renderJValue source

docStringTest name expected source =
    docSimpleTest name expected (JString source)

docListTest name expected source =
    name ~: fsep (map text expected) @=? renderJValue source

simpleTest =
    TestList[docSimpleTest "null" "null" JNull,
             docSimpleTest "true" "true" (JBool True),
             docSimpleTest "false" "false" (JBool False),
             docSimpleTest "number" "3.5" (JNumber 3.5)]

stringTest =
    TestList[docStringTest "empty string" "\"\"" "",
             docStringTest "simple string" "\"abc\"" "abc",
             docStringTest "escape chars" "\"a\\nb\\tc\"" "a\nb\tc",
             docStringTest "control char" "\"\\u000b\"" "\11",
             docStringTest "small unicode" "\"\\ufe43\"" "\xfe43",
             docStringTest "astral plane" "\"\\udbc1\\udea2\"" "\x1006a2"]

compoundTest =
    TestList[docListTest "empty array" ["[]"] (JArray []),
             docListTest "one element array" ["[\"foo\"]"]
                             (JArray [JString "foo"]),
             docListTest "many element array" ["[\"1\",", "\"2\",", "\"3\"]"]
                             (JArray [JString "1", JString "2",
                                      JString "3"]),
             docListTest "array of arrays" ["[[\"1\",", "\"2\"],",
                                            "[\"3\",", "\"4\"]]"]
                             (JArray [JArray [JString "1", JString "2"],
                                      JArray [JString "3", JString "4"]]),
             docListTest "object" ["{\"foo\": \"foo\",", "\"bar\": \"bar\"}"]
                             (JObject [("foo", JString "foo"),
                                       ("bar", JString "bar")])]

tests = TestList[simpleTest, stringTest, compoundTest]
